package com.atguigu.tingshu.order.mq;

import cn.hutool.core.util.StrUtil;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.order.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * OrderReceiver 订单Kafka监听器
 *
 * @author Petrichor
 * @version 2024/01/10 20:19
 **/
@Component
@Slf4j
public class OrderReceiver {
    private final OrderInfoService orderInfoService;

    public OrderReceiver(OrderInfoService orderInfoService) {
        this.orderInfoService = orderInfoService;
    }
    /**
     * @description: 更新订单状态的消息
     * @author Petrichor
     * @date 2024/1/10 20:21
     * @param record .value()
     * @return
    **/
    @KafkaListener(topics = KafkaConstant.QUEUE_ORDER_PAY_SUCCESS)
    public void orderPaySuccess(ConsumerRecord<String, String> record) {
        String orderNo = record.value();
        if(!StrUtil.isEmpty(orderNo)) {
            log.info("订单通知: {}", orderNo);
            orderInfoService.orderPaySuccess(orderNo);
        }
    }
}


